﻿Public Class Cuentas_por_cobrar
    Private cpc As Datos.CuentasPrestamos
    Private Shared cuentas As Cuentas_por_cobrar = Nothing
    Private cli As Datos.clientes

    Private Sub Cuentas_por_cobrar_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        cpc = Datos.CuentasPrestamos.Instanciar
        Me.BindingNavigator1.BindingSource = cpc._binding
        cli = Datos.clientes.Instanciar

        Me.ComboBox1.DataBindings.Add(New Binding("SelectedValue", cpc._binding, "IdCliente"))
        Me.ComboBox1.DataSource = cli._binding
        Me.ComboBox1.DisplayMember = "Nombre"
        Me.ComboBox1.ValueMember = "IdCliente"

        Me.DateTimePicker1.DataBindings.Add(New Binding("text", cpc._binding, "FechaIni"))
        Me.DateTimePicker2.DataBindings.Add(New Binding("text", cpc._binding, "FechaFin"))
        Me.TbMonto.DataBindings.Add(New Binding("text", cpc._binding, "Monto"))
        Me.TextBox1.DataBindings.Add(New Binding("text", cpc._binding, "Intereses"))
        Me.TextBox2.DataBindings.Add(New Binding("text", cpc._binding, "TotalPagar"))

    End Sub

    Public Shared Function instanciar() As Cuentas_por_cobrar
        If cuentas Is Nothing Then
            cuentas = New Cuentas_por_cobrar
        End If
        Return cuentas

    End Function
    Private Sub Cliente_Disposed(sender As Object, e As EventArgs) Handles Me.Disposed
        cuentas = Nothing

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim a As Decimal
        Dim b As Decimal
        Dim c As Decimal
        Dim d As Decimal

        a = Me.TbMonto.Text
        b = Me.TextBox1.Text
        c = a * b / a
        d = a + c
        Me.TextBox2.Text = d
        cpc.Insertar(Me.ComboBox1.SelectedValue, Me.TbMonto.Text, Me.DateTimePicker1.Text, Me.DateTimePicker2.Text, Me.TextBox1.Text, Me.TextBox2.Text)

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        cpc.eliminar()
    End Sub
End Class